package link.config;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.Nullable;
import org.an.proj.contacts.MyApplication;

/**
 * Created by an on 2016/12/18.<br/>
 */

public class SharedPreferencesHelper {
  private SharedPreferences mSP;
  private SharedPreferences.Editor mEditor;

  private SharedPreferencesHelper(String spName) {
    mSP = MyApplication.getInstance().getSharedPreferences(spName, Context.MODE_PRIVATE);
    mEditor = mSP.edit();
  }

  public static SharedPreferencesHelper create(String spName) {
    return new SharedPreferencesHelper(spName);
  }

  public SharedPreferencesHelper putString(String key, @Nullable String value) {
    mEditor.putString(key, value).commit();
    return this;
  }

  public String getString(String key, @Nullable String defValue) {
    return mSP.getString(key, defValue);
  }

  public SharedPreferencesHelper putBoolean(String key, boolean value) {
    mEditor.putBoolean(key, value).commit();
    return this;
  }

  public boolean getBoolean(String key, boolean defValue) {
    return mSP.getBoolean(key, defValue);
  }
}
